package com.supreme.orderserver.datamapper;

import com.supreme.common.dto.CompleteOrder;
import com.supreme.commonentity.mysql.primary.BizOrder;
import org.mapstruct.BeanMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;

import java.time.LocalDateTime;
import java.util.Date;

@Mapper(componentModel = "spring", imports = {Date.class, LocalDateTime.class}, typeConversionPolicy = ReportingPolicy.ERROR)
public interface OrderDtoMapper {

    @BeanMapping(ignoreByDefault = true)
    @Mapping(source = "orderCode", target = "orderCode")
    @Mapping(source = "orderNum", target = "saleNum")
    @Mapping(source = "orderType", target = "orderTypeStr")
    @Mapping(source = "createdAt", target = "orderCreatedAt", dateFormat = "yyyy-MM-dd HH:mm")
    @Mapping(target = "createdAt", expression = "java(LocalDateTime.now())")
    @Mapping(target = "updatedAt", expression = "java(LocalDateTime.now())")
    @Mapping(target = "completeDate", expression = "java(new Date())")
    CompleteOrder mappingToCompleteOrder(BizOrder order);
}
